package com.uetoken.cn.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.EncodeUtils;
import com.jungly.gridpasswordview.GridPasswordView;
import com.uetoken.cn.R;
import com.uetoken.cn.base.BaseActivity;
import com.uetoken.cn.utils.GlideApp;
import com.uetoken.cn.utils.KeybordUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 谢杨
 * @date 2018年7月27日16:36:20
 * 支付密码界面
 */
public class PaymentPasswordActivity extends BaseActivity {


    @BindView(R.id.iv_activity_payment_password_close)
    ImageView mIvClose;
    @BindView(R.id.tv_activity_payment_password_merchant)
    TextView mTvMerchant;
    @BindView(R.id.tv_activity_payment_password_money)
    TextView mTvMoney;
    @BindView(R.id.iv_activity_payment_password_icon)
    ImageView mIvIcon;
    @BindView(R.id.tv_activity_payment_password_pursename)
    TextView mTvPurseName;
    @BindView(R.id.tv_activity_payment_password_balance)
    TextView mTvBalance;
    @BindView(R.id.ll_activity_payment_password_payment_method)
    LinearLayout mLlPaymentMethod;
    @BindView(R.id.gpv_activity_payment_password)
    GridPasswordView mGpvPassword;

    /**
     * 当前选择的钱包的图标
     */
    private String icon;
    /**
     * 当前选择的图标的名字
     */
    private String pursename;
    /**
     * 当前选择钱包的余额
     */
    private String balance;
    /**
     * 消费金额
     */
    private String amount;
    /**
     * 商品类型
     */
    private String subject;



    @Override
    public int getLayoutId() {
        return R.layout.activity_payment_password;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        Intent intent = getIntent();
        amount = intent.getStringExtra("amount");
        subject = intent.getStringExtra("subject");
        pursename = intent.getStringExtra("pursename");
        icon = intent.getStringExtra("icon");
        balance = intent.getStringExtra("balance");

        mTvMerchant.setText(subject);
        mTvMoney.setText(amount);
        GlideApp.with(this).load(icon).placeholder(R.drawable.ic_placeholder).into(mIvIcon);
        mTvPurseName.setText(pursename);
        mTvBalance.setText(String.format(getResources().getString(R.string.str_balance), balance));


        mGpvPassword.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
            @Override
            public void onTextChanged(String psw) {
                //正在输入的密码
            }

            @Override
            public void onInputFinish(String psw) {
                //密码输入完成
                Intent inputFinishIntent = new Intent();
                inputFinishIntent.putExtra("inputFinish", EncodeUtils.base64Encode2String(psw.getBytes()));
                setResult(RESULT_OK, inputFinishIntent);
                finish();
            }
        });
    }

    @Override
    public void init() {

    }


    @OnClick({R.id.iv_activity_payment_password_close, R.id.ll_activity_payment_password_payment_method})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_activity_payment_password_close:
                if (KeybordUtils.isSoftInputShow(PaymentPasswordActivity.this)) {
                    KeybordUtils.closeKeybord(null, PaymentPasswordActivity.this);
                }
                finish();
                break;
            case R.id.ll_activity_payment_password_payment_method:
                break;
        }
    }

}
